package com.huiyeji.sort;

import java.util.ArrayList;
import java.util.Collection;
import java.util.TreeSet;

public class SortArrayList<T> extends ArrayList<T>{

    public SortArrayList(Collection<T> collection) {
        super(new TreeSetBuilder<T>(collection).build());
    }

    private static class TreeSetBuilder<T> {

        private final Collection<T> collection;

        public TreeSetBuilder (Collection<T> collection){
            this.collection = collection;
        }

        public TreeSet<T> build(){
            TreeSet<T> treeSet = new TreeSet<T>(new SortedComparator<T>());
            treeSet.addAll(collection);
            return treeSet;
        }
    }
}
